<!--
 * @Author: 高瑞寒 15932717091@163.com
 * @Date: 2022-05-17 22:48:58
 * @LastEditTime: 2022-05-19 10:41:42
 * @LastEditors: 高瑞寒 15932717091@163.com
 * @Description:角色列表
-->
<template>
  <el-card>
    <el-table :data="rolesData">
      <el-table-column
        width="90px"
        type="index"
        :label="$t('role.index')"
      ></el-table-column>
      <el-table-column
        :label="$t('role.name')"
        prop="title"
      ></el-table-column>
      <el-table-column
        :label="$t('role.desc')"
        prop="describe"
      ></el-table-column>
      <el-table-column :label="$t('role.action')">
        <template #default="{row}">
          <el-button
            type="primary"
            v-permission="['distributePermission']"
            @click="showPermissions(row.id)"
          >{{$t('role.assignPermissions')}}</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
  <Permissions
    v-model="visible"
    :roleId="currentRoleId"
  ></Permissions>
</template>

<script setup>
import { ref } from 'vue'
import { getAllRoles } from '@/api/role'
import Permissions from './components/Permissions'

// 获取角色数据
const rolesData = ref([])
const init = async () => {
  rolesData.value = await getAllRoles()
}
init()

// 分配权限
const visible = ref(false)
const currentRoleId = ref(0)
const showPermissions = (id) => {
  currentRoleId.value = id
  visible.value = true
}
</script>

<style lang="scss" scoped></style>
